#ifndef DRAGABLETAB_H
#define DRAGABLETAB_H

#include <QWidget>
#include <QPushButton>
#include <QLabel>

namespace Ui {
class DragableTab;
}
class TabsScrollArea;

/*
    继承了 QWidget GUI类
    整体功能:
        作为最小的组件类，放置在tabsScrollArea组件内，实现了操作单个页面的功能
    具体功能：
        1、提供了tabText、和closeButton和文件操作的信息
        2、拖拽相关功能的实现 集中在mouseMoveEvent，并提供了相关信号
*/

class DragableTab : public QWidget
{
    Q_OBJECT

public:
    enum class TabType{
        TEXT = 0,
        IMAGE,
        MUSIC,
        MOVIE,
        SSH,
        DEFAULT = -1
    };

public:
    explicit DragableTab(QString titleText="", DragableTab::TabType tabType=TabType::DEFAULT, QWidget *parent = nullptr);
    ~DragableTab();

    QLabel* TitleLabel() const;
    QPushButton* CloseButton() const;
    DragableTab::TabType ContentType() const;

    void SetFilePath(QString filePath);
    QString FilePath();
    std::tuple<int, int, int> GetIndex();
    void SetIndex(int DIndex, int PIndex, int TIndex);
    void SetTabsScrollArea(TabsScrollArea* tabsScrollArea);
    TabsScrollArea* GetTabsScrollArea();

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void leaveEvent(QEvent * event) override;
    void dragEnterEvent(QDragEnterEvent *event) override;
    void paintEvent(QPaintEvent* event) override;
    bool eventFilter(QObject *watched, QEvent *event) override;

private:
    Ui::DragableTab *ui;

    TabsScrollArea* mTabsScrollArea;
    TabType mTabType {TabType::DEFAULT};
    QPoint mDragStartPos;
    bool mDragReady {false};
    QString mFilePath;
    std::tuple<int, int, int> mIndex {-1, -1, -1};

private slots:
    void ClickButtonToClose();

signals:
    void dragOut(std::tuple<int, int, int> index);
    void NeedFlatPage(std::tuple<int, int, int> index);
    void clicked();
    void closeFromButton();
};

#endif // DRAGABLETAB_H
